package alg20241025;

public class Text {
    public int longestOnes(int[] nums, int k) {
        int left = 0, right = 0, n = nums.length;
        int zero = 0;    //计数器
        int len = 0;
        while(right < n){
            if(nums[right] == 0) zero++;   //进窗口
            while(zero > k){
                if(nums[left] == 0){
                    zero--;
                }
                left++;        //出窗口
            }
            len = Math.max(len, right - left + 1);
            right++;
        }
        return len;
    }
}
